
import 'package:flutter/material.dart';

class DBDashedLine extends StatelessWidget {
  final bool isHorizontal; // 方向：true 为水平，false 为垂直
  final double width; // 虚线的粗细
  final double height; // 虚线的总高度（垂直方向）或总宽度（水平方向）
  final Color color; // 虚线颜色
  final double dashWidth; // 虚线的宽度
  final double gapWidth; // 间隙的宽度
  final int count; // 虚线和间隙的总数量

  const DBDashedLine({
    super.key,
    this.isHorizontal = true,
    this.width = 1,
    this.height = 100,
    this.color = Colors.black,
    this.dashWidth = 5,
    this.gapWidth = 5,
    this.count = 10,
  });

  @override
  Widget build(BuildContext context) {
    return Flex(
      direction: isHorizontal ? Axis.horizontal : Axis.vertical,
      mainAxisSize: MainAxisSize.min,
      children: List.generate(
        count,
            (index) {
          final bool isDash = index % 2 == 0;
          return SizedBox(
            width: isHorizontal ? (isDash ? dashWidth : gapWidth) : width,
            height: isHorizontal ? width : (isDash ? dashWidth : gapWidth),
            child: DecoratedBox(
              decoration: BoxDecoration(
                color: isDash ? color : Colors.transparent,
              ),
            ),
          );
        },
      ),
    );
  }
}